package cn.xfdzx.android.apps.shop.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.CarCouponsBeen;
import cn.xfdzx.android.apps.shop.bean.CarManJianBeen;

/**
 * @author gzk
 * @date 2020/3/28 0028
 * description：领劵
 */
public class CarCouponsLVAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<CarCouponsBeen> mList;
    private TextView tv_price;
    private TextView tv_man_can;
    private TextView tv_title;
    private TextView tv_content_can;
    private TextView tv_time_can;
    private TextView tv_is_can;

    public CarCouponsLVAdapter(Context mContext, ArrayList<CarCouponsBeen> mList){
        this.mContext=mContext;
        this.mList=mList;
        addData();
    }

    private void addData() {
        mList.add(new CarCouponsBeen(8,"满49可用","新人首单立减","新人专享","从领取之日起3天有效",false));
        mList.add(new CarCouponsBeen(8,"满49可用","新人首单立减","新人专享","从领取之日起3天有效",true));
        mList.add(new CarCouponsBeen(8,"满49可用","新人首单立减","","从领取之日起3天有效",false));
    }

    @Override
    public int getCount() {
        return 3;
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        view=View.inflate(mContext, R.layout.item_car_coupons,null);
        tv_price= view.findViewById(R.id.tv_price);
        tv_man_can= view.findViewById(R.id.tv_man_can);
        tv_title= view.findViewById(R.id.tv_title);
        tv_content_can= view.findViewById(R.id.tv_content_can);
        tv_time_can= view.findViewById(R.id.tv_time_can);
        tv_is_can=view.findViewById(R.id.tv_is_can);

        tv_price.setText("¥"+mList.get(i).price);
        tv_man_can.setText(mList.get(i).man_can);
        tv_title.setText(mList.get(i).title);
        if (mList.get(i).content_can.isEmpty()){
            tv_content_can.setVisibility(View.GONE);
        }else {
            tv_content_can.setVisibility(View.VISIBLE);
        }
        tv_content_can.setText(mList.get(i).content_can);
        tv_time_can.setText(mList.get(i).time_can);
        if (mList.get(i).receive){
            tv_is_can.setText("已领取");
            tv_is_can.setBackgroundResource(R.drawable.item_car_ling_hui_bg);
            tv_is_can.setTextColor(mContext.getResources().getColor(R.color.color_B7B7B7));
        }else {
            tv_is_can.setText("领取");
            tv_is_can.setBackgroundResource(R.drawable.item_car_ling_bg);
            tv_is_can.setTextColor(mContext.getResources().getColor(R.color.color_FFFFFF));
            tv_is_can.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mList.get(i).receive=true;
                    notifyDataSetChanged();
                    Toast.makeText(mContext,"已领取",Toast.LENGTH_SHORT).show();
                }
            });
        }


        return view;
    }
}
